package com.xx.xunyou.serviceImpl;

import com.xx.xunyou.dao.item.chizhuzaixiang.ChizhuzaixiangContentDAO;
import com.xx.xunyou.dao.item.chizhuzaixiang.ChizhuzaixiangDAO;
import com.xx.xunyou.entity.item.chizhuzaixiang.Chizhuzaixiang;
import com.xx.xunyou.entity.item.chizhuzaixiang.ChizhuzaixiangContent;
import com.xx.xunyou.entity.item.chizhuzaixiang.vo.ChizhuzaixiangVo;
import com.xx.xunyou.service.ChizhuzaixiangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author: zhl
 * @Description:
 */
@Service
public class ChizhuzaixiangServiceImpl implements ChizhuzaixiangService {

    @Autowired
    private ChizhuzaixiangDAO chizhuzaixiangDAO;

    @Autowired
    private ChizhuzaixiangContentDAO chizhuzaixiangContentDAO;

    @Override
    public Integer queryListCountToManager(Map<String, Object> map) {
        return chizhuzaixiangDAO.queryListCountToManager(map);
    }

    @Override
    public List<Map> queryListToManager(Map<String, Object> map) {
        return chizhuzaixiangDAO.queryListToManager(map);
    }

    @Override
    @Transactional
    public void insert(Chizhuzaixiang chizhuzaixiang, String content) {
        Date date = new Date();
        chizhuzaixiang.setCreateTime(date);
        chizhuzaixiangDAO.insertBackId(chizhuzaixiang);
        //内容
        ChizhuzaixiangContent chizhuzaixiangContent1 = new ChizhuzaixiangContent();
        chizhuzaixiangContent1.setChizhuzaixiangId(chizhuzaixiang.getChizhuzaixiangId());
        chizhuzaixiangContent1.setContent(content);
        chizhuzaixiangContent1.setCreateTime(date);
        chizhuzaixiangContentDAO.insert(chizhuzaixiangContent1);
    }

    @Override
    public Chizhuzaixiang queryByIdToManager(Integer chizhuzaixiangId) {
        return chizhuzaixiangDAO.selectByPrimaryKey(chizhuzaixiangId);
    }

    @Override
    public ChizhuzaixiangContent queryContentByIdToManager(Integer chizhuzaixiangId) {
        return chizhuzaixiangContentDAO.selectByPrimaryKey(chizhuzaixiangId);
    }

    @Override
    @Transactional
    public void update(Chizhuzaixiang chizhuzaixiang, String content) {
        chizhuzaixiangDAO.updateByPrimaryKeySelective(chizhuzaixiang);
        //内容
        ChizhuzaixiangContent chizhuzaixiangContent1 = new ChizhuzaixiangContent();
        chizhuzaixiangContent1.setChizhuzaixiangId(chizhuzaixiang.getChizhuzaixiangId());
        chizhuzaixiangContent1.setContent(content);
        chizhuzaixiangContentDAO.updateByPrimaryKeySelective(chizhuzaixiangContent1);
    }

    @Override
    @Transactional
    public void delete(Integer chizhuzaixiangId) {
        chizhuzaixiangDAO.deleteByPrimaryKey(chizhuzaixiangId);
        chizhuzaixiangContentDAO.deleteByPrimaryKey(chizhuzaixiangId);
    }

    @Override
    @Transactional
    public void recommend(Integer chizhuzaixiangId) {
        chizhuzaixiangDAO.recommend(chizhuzaixiangId,new Date());
    }

    @Override
    @Transactional
    public void notRecommend(Integer chizhuzaixiangId) {
        chizhuzaixiangDAO.notRecommend(chizhuzaixiangId);
    }

    @Override
    public List<ChizhuzaixiangVo> queryListToAPPIndex(Map<String, Object> map) {
        return chizhuzaixiangDAO.queryListToAPPIndex(map);
    }

    @Override
    public List<Chizhuzaixiang> querByMapToAPPPageRecommend(Map<String, Object> map) {
        return chizhuzaixiangDAO.querByMapToAPPPageRecommend(map);
    }

    @Override
    public List<Chizhuzaixiang> querByMapToAPPPage(Map<String, Object> map) {
        return chizhuzaixiangDAO.querByMapToAPPPage(map);
    }

    @Override
    public Integer querByMapToAPPTotal(Map<String, Object> map) {
        return chizhuzaixiangDAO.querByMapToAPPTotal(map);
    }
}
